﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Threading;

namespace directory
{
    class Program
    {
        /// <summary>
        /// Set person into Dictionary
        /// </summary>
        /// <returns>Person Name</returns>
        static string getPersoneName()
        {
            Console.WriteLine("Please input person Last Name");
            string s = Console.ReadLine();

            foreach (char c in s.ToLower().ToCharArray())
            {
                if ((Convert.ToInt32(c) > 122) || (Convert.ToInt32(c) < 97))
                {
                    Console.WriteLine("Wrong name input - please make sure it caontains only letters");
                    return getPersoneName();
                }
            }
            return s;
        }
        /// <summary>
        /// Set person number into Dictionary
        /// </summary>
        /// <returns>Person Number</returns>
        static int getPersoneNumber()
        {
            Console.WriteLine("Please input person Phone Number");
            string s = Console.ReadLine();

            try
            {
                Convert.ToInt32(s);
            }
            catch (FormatException)
            {
                Console.WriteLine("Wrong input\nPlease put only digits");
                return getPersoneNumber();
            }

            if ((Convert.ToInt32(s) < 70000) && (Convert.ToInt32(s) >= 60000))
            {
                return Convert.ToInt32(s);
            }
            else
            {
                Console.WriteLine("Wrong input\nPlease input number in range of 60000 - 69999");
                return getPersoneNumber();
            }
        }
        /// <summary>
        /// Looking for a person by phone number
        /// </summary>
        /// <param name="dictionary">Need to pass array of strings</param>
        static void FindPerson(string[] dictionary)
        {
            bool quit;
            do
            {
                Console.WriteLine(dictionary[getPersoneNumber()]);
                Thread.Sleep(1000);
                quit = recursiveQuestion();
            } while (quit == true);
        }
        /// <summary>
        /// Repitedly ask question for continue or stop
        /// </summary>
        /// <returns>bool value True = go/ false = stop</returns>
        static bool recursiveQuestion()
        {
            Console.WriteLine("One more? y/n");
            string s = (Console.ReadLine()).ToLower();
            if ((s == "y") || (s == "yes"))
            {
                return true;
            }
            else if ((s == "n") || (s == "no"))
            {
                return false;
            }
            else
            {
                Console.WriteLine("Wrong input - please make sure you put y/yes/Y/YES or n/No/N/NO");
                return recursiveQuestion();
            }
            
        }
        /// <summary>
        /// Dictinary that contains persons list
        /// </summary>
        private static string[] dictionary = new string[80000];
        /// <summary>
        /// Filling out the dictionary
        /// </summary>
        static void AddPerson()
        {
            bool quit;
            do
            {
                dictionary[getPersoneNumber()] = getPersoneName();
                quit = recursiveQuestion();
            } while (quit == true);
        }

        static void Main(string[] args)
        {
            AddPerson();
            FindPerson(dictionary);
        }
    }
}
